package com.lam.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lam.common.base.domain.Result;
import com.lam.framework.operLog.annotation.Log;
import com.lam.monitor.domain.RedisInfo;
import com.lam.monitor.service.RedisService;

@Log(title = "Redis监控")
@RestController
@RequestMapping("/${adminPath}/monitor/redis")
public class RedisController {
	
	    @Autowired
    private RedisService redisService;

    /**
     * Redis详细信息
     * @return
     * @throws Exception
     */
    @Log(oper="Redis详情")
    @PreAuthorize("@ss.hasPm('monitor:redis:info')")
    @GetMapping("/info")
    public Result getRedisInfo() {
        List<RedisInfo> infoList = redisService.getRedisInfo();
        infoList.sort((o1, o2)->o1.getKey().compareTo(o2.getKey()));
        return Result.ok(infoList);
    }

    @Log(oper="KeySize")
    @PreAuthorize("@ss.hasPm('monitor:redis:keySize')")
    @GetMapping("/keysSize")
    public Result getKeysSize() {
    	
        return Result.ok(redisService.getKeysSize().entrySet());
    }
    
    @Log(oper="memoryInfo")
    @PreAuthorize("@ss.hasPm('monitor:redis:memoryInfo')")
    @GetMapping("/memoryInfo")
    public Result getMemoryInfo() {
        return Result.ok(redisService.getMemoryInfo());
    }

    /**
     * 获取redis key数量 for 报表
     * @return
     * @throws Exception
     */
    @Log(oper="keysSizeForReport")
    @PreAuthorize("@ss.hasPm('monitor:redis:keysSizeForReport')")
    @GetMapping("/keysSizeForReport")
    public Result getKeysSizeReport() {
		return Result.ok(redisService.getMapForReport("1"));
    }
    /**
     * 获取redis 内存 for 报表
     *
     * @return
     * @throws Exception
     */
    @Log(oper="memoryForReport")
    @PreAuthorize("@ss.hasPm('monitor:redis:memoryForReport')")
    @GetMapping("/memoryForReport")
    public Result memoryForReport() {
		return Result.ok(redisService.getMapForReport("2"));
    }
    /**
     * 获取redis 全部信息 for 报表
     * @return
     * @throws Exception
     */
    @Log(oper="infoForReport")
    @PreAuthorize("@ss.hasPm('monitor:redis:infoForReport')")
    @GetMapping("/infoForReport")
    public Result infoForReport() {
		return Result.ok(redisService.getMapForReport("3"));
    }

}
